package org.example.Contant;


import lombok.Data;

@Data
public class Result <T>{

    private String code;

    private String description;

    private T data;

    private ErrorCode errorCode;

    /**
     * 返回成功
     * @param code
     * @param data
     * @return
     * @param <T>
     */
    public static <T> Result<T> success(String code, T data){
        Result<T> result = new Result<>();
        result.code = code;
        result.data = data;
        return result;
    }

    /**
     * 返回错误
     * @param code
     * @param errorCode
     * @return
     * @param <T>
     */
    public static <T> Result<T> error(String code, ErrorCode errorCode){
        Result<T> result = new Result<>();
        result.code = code;
        result.errorCode = errorCode;
        return result;
    }

    /**
     * 返回错误
     * @param code
     * @param description
     * @return
     * @param <T>
     */
    public static <T> Result<T> error(String code,String description){
        Result<T> result = new Result<>();
        result.code = code;
        result.description = description;
        return result;
    }
}
